package com.zlop.cloud.business.api.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
	
	private final Logger logger = LoggerFactory.getLogger(getClass());
	
	@Value("${server.port}")
	private String serverPort;
	
	@GetMapping("/listUsers")
    public String listUsers(HttpServletRequest request){
		logger.info("===<call trace-2, TraceId={}, SpanId={}, ParentSpanId={}>===", 
				request.getHeader("X-B3-TraceId"), request.getHeader("X-B3-SpanId"), request.getHeader("X-B3-ParentSpanId"));
        List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();
        for(int i=1; i< 5; i++){
            Map<String, Object> user = new HashMap<String, Object>();
            user.put("id", i);
            user.put("name", "小明" + i);
            users.add(user);
        }
        return "服务器端口号：   " + serverPort + "   |   用户信息：   " + users.toString();
    }
	
}
